package edu.zut.cn.controller;


import edu.zut.cn.domain.ResponseResult;
import edu.zut.cn.domain.entity.User;
import edu.zut.cn.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 *  LoginController
 *
 * @author 张小訫
 */
@RestController
@Api(tags = "Login",description = "登录相关接口")
public class LoginController {

    @Autowired
    private LoginService loginService;

    @PostMapping("/login")
    @ApiOperation(value = "登录", notes = "进行登录验证")
    public ResponseResult login(@RequestBody User user , HttpServletRequest request) {
        return loginService.Login(user, request.getSession());
    }

    @PostMapping("/logout")
    @ApiOperation(value = "退出",notes = "退出登录")
    public ResponseResult logout(HttpSession session){
        return loginService.logout(session);
    }
}